angular.module('imsApp').controller('campaignsStatisticsController', ['$scope', '$rootScope', '$state', 'CampaignsManager', function ($scope, $rootScope, $state, CampaignsManager) {
    $scope.search = {
        campaignsId: $state.params.campaignsId,
        timeType: $state.params.timeType || 'day',
        pageNo: $state.params.pageNo || 1,
        pageSize: $state.params.pageSize || 10
    };
    $scope.paginationDetail = {
        currentPage: $scope.search.pageNo,
        itemsPerPage: $scope.search.pageSize,
        pagesLength: 9,
        search: 0,
        onChange: function () {
            $scope.search.pageNo = this.currentPage;
            $scope.search.pageSize = this.itemsPerPage;
            $state.go($state.current.name, {
                campaignsId: $scope.search.campaignsId,
                pageNo: $scope.search.pageNo,
                pageSize: $scope.search.pageSize,
                timeType: 'day'
            }, {inherit: false})

        }
    };


    CampaignsManager.campaignsStatistics([$scope.search.campaignsId, $scope.paginationDetail.currentPage, $scope.paginationDetail.itemsPerPage], {timeType: $scope.search.timeType}).then(function (result) {
        $scope.campaignsStatisticsList = result.data;
        console.log(result)
        if ($scope.campaignsStatisticsList.c == "s") {
            $scope.lists = $scope.campaignsStatisticsList.pageList;
            $scope.total = $scope.campaignsStatisticsList.countStat;
            $scope.paginationDetail.totalItems =$scope.campaignsStatisticsList.total;
            $scope.title = $scope.campaignsStatisticsList.title;
            $scope.uTime = $scope.campaignsStatisticsList.uTime;
        }

    })

    $scope.timeTypeChange = function (type) {
        $state.go($state.current.name, {
            campaignsId: $scope.search.campaignsId,
            pageNo: 1,
            pageSize: 10,
            timeType: type
        }, {inherit: false})
    }


}])

